﻿CREATE TABLE [dbo].[tblOrderHeader] (
    [OrderID]              INT           IDENTITY (1, 1) NOT NULL,
    [CustomerID]           INT           NOT NULL,
    [OrderDate]            SMALLDATETIME NOT NULL,
    [ProjShipDate]         SMALLDATETIME NOT NULL,
	[OrderSourceID]		INT NULL,
    [ProductTotal]         MONEY         NOT NULL,
    [Shipping]             MONEY         NULL,
    [Taxes]                MONEY         NOT NULL,
    [OrderTotal]           MONEY         NOT NULL,
	[OrderOriginCode]	char(1) NULL,
    [ImportDate]           DATETIME      NOT NULL,
    [DetailCount]          SMALLINT      NULL,
    [HoldReasonCode]       CHAR (1)      NULL,
    [AccountID]            INT           NULL,
	[BankCheckNumber]	   INT			 NULL,
    [ShipTo_PersonID]      INT           NULL,
    [ShipTo_CompanyName]   NVARCHAR (50) NULL,
    [ShipTo_AddressID]     INT           NOT NULL,
    [AgentID]              INT           NULL,
	[PrePaid]			   bit			 null,
	[PromotionID]		   int			 null,
    [OrderStatusCode]      CHAR (1)      NULL,
    [CanceledReasonID]     INT           NULL,
	[CanceledDate]		   SMALLDATETIME NULL,
    [PreferredCarrierCode] int		     NULL,
    [OwnerID]              INT           NOT NULL,
	[ImportBatchID]		   int			 null,
	[InvoiceDate]		   smalldatetime null,
	[SequenceOrderStepID]  INT			 NULL,
	[SequenceCount]		   INT			 NULL,
	[ProcessorCode]		char(1) null,
	[UserDefined1]         NVARCHAR (50)  NULL,
	[UserDefined2]         NVARCHAR (50)  NULL,
	[UserDefined3]         NVARCHAR (10)  NULL,
	[UserDefined4]         NVARCHAR (10)  NULL,
	[UserDefined5]         INT            NULL,
	[UserDefined6]         INT            NULL,
	[UserDefined7]         SMALLDATETIME  NULL,
	[UserDefined8]         BIT            NULL,
	[UserDefined9]         BIT            NULL
);
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Defines an order.', @level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'primary key.  Uniquely identifies each order.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OrderID';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The customer number of the customer to whom this order belongs.  Links to tblCustomer.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'CustomerID';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The date the order was taken', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OrderDate';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The date the order is expected to ship', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'ProjShipDate';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Linked to tblOrderSource.  Defines the media tracking code to source the order to.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OrderSourceID';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Linked to codeOrderOrigin.  Defines where the order phisically came from (web, imported, C/S, etc...)', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OrderOriginCode';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Linked to codeHoldReason.  If the order status is H then this field defines the reason the order is on hold.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'HoldReasonCode';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Linked to tblAccount.  Defines the account that this order bills to.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'AccountID';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Linked to tblPerson.  Defines who this order ships to.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'ShipTo_PersonID';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'This is set to 1 to indicate the order has been prepaid before import.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'Prepaid';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Linked to codeOrderStatus.  Defines the current status of the order.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OrderStatusCode';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Linked to tblCanceledReason.  If the order status is Canceled, this defines the cancelation reason code.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'CanceledReasonID';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'If the order status is Canceled, this defines the date/time the order was canceled.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'CanceledDate';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Links to tblOwner.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OwnerID';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Links to codeCarrier.  If this is set then the order will ship by the specified carrier if possible.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'PreferredCarrierCode';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Qty * UnitPrice * (1 - Discount)', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'ProductTotal';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The shipping cost for the order.  Shipping is allowed to be null to allow for processing to decide when to calculate shipping.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'Shipping';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Any applicable state sales tax.  Detailed in tblOrderTax', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'Taxes';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'ProductTotal + Shipping + Taxes.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OrderTotal';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The date the record was imported into tblOrderHeader', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'ImportDate';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The number of order detail records.  This is used as a validation on import to insure that the correct number of detail records have been imported.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'DetailCount';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The ID of the Agent who took the order', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'AgentID';
Go;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Links to tblSequenceOrderStep.  Defines the SequenceOrderStep responsible for creating this order.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'SequenceOrderStepID';
Go;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Defines the repitition number or this order within the reference SequenceOrderStep.  For instance, it this value is 2 then this is the second order created by the referenced SequenceOrderStep.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'SequenceCount';
Go;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Links to codePaymentProcessor.  Indicates the payment processor which should be used to process transactions for this order.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'ProcessorCode';
Go;
